package org.summerframework.component.enums.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.summerframework.component.enums.model.dao.EnumsDAO;
import org.summerframework.component.enums.model.domain.EnumsDO;
import org.summerframework.component.enums.service.EnumsService;
import org.summerframework.component.enums.service.dto.EnumsDTO;
import org.summerframework.component.enums.service.dto.EnumsQueryDTO;
import org.summerframework.component.mybatisplus.AbstractBasePlusService;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service("enumsService")
public class EnumsServiceImpl extends AbstractBasePlusService<EnumsDAO, EnumsDTO, EnumsQueryDTO, EnumsDO> implements EnumsService {

    @Override
    public Wrapper<EnumsDO> getWrapper(EnumsQueryDTO query) {
        return Wrappers.<EnumsDO>lambdaQuery()
.eq(Objects.nonNull(query.getCode()), EnumsDO::getCode, query.getCode())
.orderBy(Objects.nonNull(query.getOrderBySortIndex()), query.getOrderBySortIndex() != null?query.getOrderBySortIndex():false, EnumsDO::getSortIndex)
.eq(StringUtils.isNotBlank(query.getKind()), EnumsDO::getKind, query.getKind())
.eq(Objects.nonNull(query.getIsVisible()), EnumsDO::getIsVisible, query.getIsVisible())
.orderBy(Objects.nonNull(query.getOrderById()), query.getOrderById() != null?query.getOrderById():false, EnumsDO::getId)
.eq(StringUtils.isNotBlank(query.getGroup()), EnumsDO::getGroup, query.getGroup());
    }
}
